/**
 * Copyright &copy; 2012-2016 <a href="https://git.oschina.net/zdw2016/webbase5">Webbase</a> All rights reserved.
 */
package com.foreveross.webbase.project.web;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.foreveross.webbase.common.config.Global;
import com.foreveross.webbase.common.persistence.Page;
import com.foreveross.webbase.common.web.BaseController;
import com.foreveross.webbase.common.utils.StringUtils;
import com.foreveross.webbase.project.entity.SysSpServle;
import com.foreveross.webbase.project.service.SysSpServleService;

/**
 * 服务器管理Controller
 * @author yangwanli
 * @version 2017-03-13
 */
@Controller
@RequestMapping(value = "${adminPath}/project/sysSpServle")
public class SysSpServleController extends BaseController {

	@Autowired
	private SysSpServleService sysSpServleService;
	
	@RequiresPermissions("project:sysSpServle:view")
	@RequestMapping(value = {"list", ""})
	public String list(SysSpServle sysSpServle) {
		Page<SysSpServle> page = sysSpServleService.findPage(new Page<SysSpServle>(request(), response()), sysSpServle); 
		attr("page", page);
		return "project/sysSpServleList";
	}
	@RequiresPermissions("project:sysSpServle:view")
	@RequestMapping("obj")
	@ResponseBody
	public List<SysSpServle> listServle(SysSpServle sysSpServle) {
		List<SysSpServle> findObj=sysSpServleService.findList(sysSpServle);
		return findObj;
	}
	@RequiresPermissions("project:sysSpServle:view")
	@RequestMapping("form")
	public String form(String id) {
		if(StringUtils.isNotEmpty(id)) {
			SysSpServle sysSpServle=sysSpServleService.get(id);
			attr("sysSpServle", sysSpServle);
		} else {
			attr("sysSpServle", new SysSpServle());
		}
		return "project/sysSpServleForm";
	}

	@RequiresPermissions("project:sysSpServle:edit")
	@RequestMapping("save")
	public String save(SysSpServle sysSpServle, RedirectAttributes redirectAttributes) {
		if (!beanValidator(redirectAttributes, sysSpServle)){
			return form(sysSpServle.getId());
		}
		sysSpServleService.save(sysSpServle);
		addMessage(redirectAttributes, "保存服务器成功");
		return "redirect:"+Global.getAdminPath()+"/project/sysSpServle/?repage";
	}
	
	@RequiresPermissions("project:sysSpServle:edit")
	@RequestMapping("delete")
	public String delete(@RequestParam String id, RedirectAttributes redirectAttributes) {
		sysSpServleService.delete(id);
		addMessage(redirectAttributes, "删除服务器成功");
		return "redirect:"+Global.getAdminPath()+"/project/sysSpServle/?repage";
	}

}